package com.mall.dao;

import com.mall.domain.ItemGoods;
import com.mall.domain.Page;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 商品的持久化层
 * @author : liangY
 * @date : 2021-01-12 16:02
 */
@Repository
public interface IItemGoodsDao {

    /**
     * 查询所有商品
     * @param page 分页实体类
     * @return
     */
    @Select("select * from tb_item_goods where goods_name like #{page.query} limit #{page.num},#{page.size}")
    List<ItemGoods> findAll(@Param("page") Page page);

    @Select("select * from tb_item_goods where goods_id = #{goods_id}")
    List<ItemGoods> findAb(Integer goods_id);
    /**
     * 查询所有商品
     * @param
     * @return
     */
    @Select("select * from tb_item_goods ")
    List<ItemGoods> findAll1();
    /***
     * 查询所有商品,随机显示15条
     */
    @Select("select * from tb_item_goods  order by rand() limit 15 " )
    List<ItemGoods> findAllimg();
    /**
     * 查询所有商品
     * @param page 分页实体类
     * @return
     */
    @Select("select * from tb_item_goods where status=1 and goods_name like #{page.query} limit #{page.num},#{page.size}" )
    List<ItemGoods> findAlls(@Param("page") Page page);

    /**
     * 查询所有商品数量
     * @return
     */
    @Select("select count(*) from tb_item_goods")
    Integer findTotal();

    /**
     * 更新商品
     * @param itemGoods 商品实体类
     * @return
     */
    @Update("update tb_item_goods set cat_name=#{cat_name},goods_introduce=#{goods_introduce},store_location=#{store_location},goods_name=#{goods_name},goods_price=#{goods_price}," +
            "status=#{status},goods_big_logo=#{goods_big_logo} where goods_id=#{goods_id}")
    Integer update(ItemGoods itemGoods);
    /**
     * 添加商品
     * @param itemGoods 商品实体类
     * @return
     */
    @Insert("insert into tb_item_goods (cat_name,store_location,goods_name,goods_price,goods_introduce,goods_big_logo)values(#{cat_name},#{store_location},#{goods_name},#{goods_price},#{goods_introduce},#{goods_big_logo})")
    @SelectKey(keyColumn = "goods_id", keyProperty = "goods_id", resultType = Integer.class,
            before = false, statement = {"select last_insert_id()"})
    Integer add(ItemGoods itemGoods);

    /**
     * 删除商品
     * @param goods_id 商品编号
     * @return
     */
    @Delete("delete from tb_item_goods where goods_id = #{goods_id}")
    Integer del(Integer goods_id);
}
